<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
  <head>    
    <title>获取用户数据并计算</title>
  </head>
 
  <body bgcolor="yellow">
  	<%
  		String str1=request.getParameter("num1");
  		String str2=request.getParameter("num2");
  		String opt=request.getParameter("opt"); 
  		if(str1==null)
  			str1="0";
  		if(str2==null)
  			str2="0";
  		
  		try{
  			double n1=Double.parseDouble(str1);
  			double n2=Double.parseDouble(str2);
  			double sum=0;
  			if(opt.equals("+")){
  				sum=n1+n2;
  			}else if(opt.equals("-")){
  				sum=n1-n2;
  			}else if(opt.equals("*")){
  				sum=n1*n2;
  			}else if(opt.equals("/") && n2!=0){
  				sum=n1/n2;
  			}
  			out.print(n1+opt+n2+"="+sum);
  		}catch(Exception e){
  			out.print("请输入数字类型字符！");
  		}
  	 %>
  </body>
</html>
